import axios from 'axios';

export function request(config) {
    if(config==null){
        throw new Error("config配置文件为空")
    }
    let url=config.url;
    let timeout=config.timeout?config.timeout:3000;
    let params=config.params;

    const instance=axios.create({
        url:url,
        timeout:timeout,
        params:params
    });

    //请求拦截器
    instance.interceptors.request.use(config=>{
        //console.log(config);
        console.log("这是请求前的拦截器");
        return config;
    },error => {
        console.log("请求前发生错误：",error);
    });
    //响应拦截器
    instance.interceptors.response.use(config=>{
        //console.log(config);
        console.log("这是请求后的拦截器");
        return config;
    },error => {
        console.log("请求后发生错误：",error);
    });

    return instance(config);
}